
const {ccclass, property, requireComponent, menu} = cc._decorator;

@ccclass
@requireComponent(cc.Button)
@menu("按钮/音效")
export default class ButtonAudio extends cc.Component {

    @property(cc.AudioClip)
    audio: cc.AudioClip = null;

    start () {
        var clickEventHandler = new cc.Component.EventHandler();
        clickEventHandler.target = this.node; // 这个 node 节点是你的事件处理代码组件所属的节点
        clickEventHandler.component = "ButtonAudio";// 这个是代码文件名
        clickEventHandler.handler = "callback";
        clickEventHandler.customEventData = "";

        var button = this.node.getComponent(cc.Button);
        button.clickEvents.push(clickEventHandler);
    }
    
    callback() {
        this.audio && cc.audioEngine.playEffect(this.audio, false);
    }

}
